<template>
    <view class="goods-info-txt">
        <view class="i-title ">
            <view class="i-title no-yy-box" v-if="tabArr.length > 0">
                <view class="item font_size14" :class="item.id == curTabId ? 'active bold' : ''"
                    v-for="(item, index) in tabArr" :key="index" @click="onClickTabItem(item, index)"
                    v-if="![5, 6, 9, 10, 11].includes(item.id) && item.access">
                    {{ item.title }}
                    <view :class="item.id == curTabId ? 'active-s' : ''"></view>
                </view>
            </view>
            <view class="i-title yy-box ml10" v-if="tabArr.length > 0 && tabArr.some(item => [5, 6, 9, 10, 11].includes(item.id) && item.access)">
                <view class="item font_size14" :class="item.id == curTabId ? 'active bold' : ''"
                    v-for="(item, index) in tabArr" :key="index" @click="onClickTabItem(item, index)"
                    v-if="[5, 6, 9, 10, 11].includes(item.id) && item.access">
                    {{ item.title }}
                    <view :class="item.id == curTabId ? 'active-s' : ''"></view>
                </view>
            </view>
        </view>
        <view class="list-box overflow-box">
            <!-- 客户跟进记录 -->
            <view v-show="curTabId == 1" class="FollowUpBox">
                <view class="FollowUpDiv">
                    <el-select style="width: 130px" @change="selectFun($event, 'cid')" v-model="followUpParam.cid"
                        placeholder="选择跟进类别" size="mini">
                        <el-option v-for="(item, cat) in txt_cat_ls" :key="cat" :label="item.title" :value="item.id">
                        </el-option>
                    </el-select>
                    <el-select style="width: 130px;  margin-left: 10px;" @change="selectFun($event, 'ucp_ls')"
                        v-model="followUpParam.uid_cp" placeholder="   " size="mini">
                        <el-option v-for="(item, u) in ucp_ls" :key="u" :label="item.name" :value="item.uid">
                        </el-option>
                    </el-select>
                    <el-select style="width: 130px; margin-left: 10px;" @change="selectFun($event, 't_type')"
                        v-model="followUpParam.t_type" placeholder="选择日期" size="mini">
                        <el-option v-for="(item, t) in group_ls" :key="t" :label="item.title" :value="item.id">
                        </el-option>
                    </el-select>
                    <el-button style="margin-left: 10px" @click="FollowUpListDialogIsShow('addFollowUpShow')"
                        size="mini" type="primary">增加跟进记录</el-button>
                    <el-button size="mini" @click="FollowUpListDialogIsShow('addCategoryShow')">编辑跟进类别</el-button>
                </view>
                <FollowUpList :isDrawerStatus="isDrawerStatus" :list="tabArr[listIndex].list"
                    :add_txt_cat_ls="add_txt_cat_ls" :customerId="customerId" ref="FollowUpList" @upDataFun="upDataFun">
                </FollowUpList>
            </view>
            <!-- 产品销售记录 -->
            <productSales v-if="tabArr[listIndex].list.length" v-show="curTabId == 2" :list="tabArr[listIndex].list"
                :md="md">
            </productSales>
            <empty v-else-if="curTabId == 2"></empty>
            <!-- 历史订单组件 -->
            <HistoricalOrders v-if="tabArr[listIndex].list.length" v-show="curTabId == 3"
                :list="tabArr[listIndex].list">
            </HistoricalOrders>
            <empty v-else-if="curTabId == 3"></empty>
            <!-- 收款流水组件 -->
            <CollectionFlow v-if="tabArr[listIndex].list.length" v-show="curTabId == 4" :list="tabArr[listIndex].list"
                @showFlowDetails="showFlowDetails"></CollectionFlow>
            <empty v-else-if="curTabId == 4"></empty>
            <!-- 产品销售组件 -->
            <productSales v-if="tabArr[listIndex].list.length" v-show="curTabId == 5" :list="tabArr[listIndex].list"
                :md="md">
            </productSales>
            <empty v-else-if="curTabId == 5"></empty>
            <!-- 历史订单组件 -->
            <HistoricalOrders v-if="tabArr[listIndex].list.length" v-show="curTabId == 6"
                :list="tabArr[listIndex].list">
            </HistoricalOrders>
            <empty v-else-if="curTabId == 6"></empty>
            <!-- 服务收款流水 -->
            <CollectionFlow v-if="tabArr[listIndex].list.length" v-show="curTabId == 7" :list="tabArr[listIndex].list"
                @showFlowDetails="showFlowDetails"></CollectionFlow>
            <empty v-else-if="curTabId == 7"></empty>
            <!-- 分销记录 -->
            <view v-if="curTabId == 8" class="FollowUpBox">
                <view class="mb10">
                    <el-select size="mini" style="width: 130px;margin-right: 10px;" v-model="idyun" placeholder="请选择"
                        @change="selectFunYunShop">
                        <el-option v-for="(item, ix) in getYunShopList" :key="ix" :label="item.name" :value="item.id">
                        </el-option>
                    </el-select>
                    <el-button size="mini" :type="getCustomerRecommendIndex == 1 ? 'primary' : ''"
                        @click="clickTabDistr(1)">一级分销（{{ customRecommendObj.total_1 || 0 }}）</el-button>
                    <el-button size="mini" :type="getCustomerRecommendIndex == 2 ? 'primary' : ''"
                        @click="clickTabDistr(2)">二级分销（{{ customRecommendObj.total_2 || 0 }}）</el-button>
                    <el-tag @close="elTagFlag = false" style="height: 29px;line-height: 29px; margin-left: 10px;"
                        type="warning">
                        客户上级信息：
                        <span v-if="customRecommendObj.cu_info2">
                            <span> <i class="el-icon-user-solid mr5"></i>{{ customRecommendObj.cu_info2.name }}</span>
                            <span class="ml10"> <i class="el-icon-phone mr5"></i>{{
                                customRecommendObj.cu_info2.cellphone }}</span>
                        </span>
                        <span v-else>暂无</span>
                    </el-tag>
                </view>
                <CustomerRecommend v-if="tabArr[listIndex].list && tabArr[listIndex].list.length > 0"
                    :list="tabArr[listIndex].list" :customerId="customerId" :isDrawerStatus="isDrawerStatus">
                </CustomerRecommend>
                <empty v-else="(!tabArr[listIndex].list || tabArr[listIndex].list.length == 0 )"></empty>
            </view>
            <!-- 项目服务 -->
            <view v-if="curTabId == 9" class="FollowUpBox">
                <popRemainingWinTab ref="popRemainingWinTabRef" :customId="getYyInfoData.id"
                    :customInfo="getYyInfoData"></popRemainingWinTab>
            </view>
            <!-- 卡项服务 -->
            <view v-if="curTabId == 10" class="FollowUpBox">
                <popmyCardLsWinTab ref="popmyCardLsWinTabRef" :customId="getYyInfoData.id" :customInfo="getYyInfoData">
                </popmyCardLsWinTab>
            </view>
            <!-- 智能分析 -->
            <view v-if="curTabId == 11" class="analysisBox">
                <intelligentAnalysis ref="intelligentAnalysisRef" :customId="getYyInfoData.id"
                    :customInfo="getYyInfoData"></intelligentAnalysis>
            </view>
            <!-- 跟进记录组件 -->
            <!-- 历史订单组件 -->
            <!-- <HistoricalOrders
                v-show="curTabId == 6"
                :list="tabArr[5].list"
            ></HistoricalOrders> -->
            <!-- 收款流水组件 -->
        </view>
        <ayjDialog title="收款流水详情" ref="dialogBillRef" :slotFooter="false" width="30%">
            <CollectionFlowDetails ref="CollectionFlowDetailsRef" />
        </ayjDialog>
    </view>
</template>

<script>
import accessCtrl from "@/js/limit/AccessCtrl.js"; // 检测权限
import productSales from "./ProductSales.vue";
import HistoricalOrders from "./HistoricalOrders.vue";
import CollectionFlow from "./CollectionFlow.vue";
import FollowUpList from "./followUpList.vue";
import staticConst from "../../js/const/StaticConst.js";
import lang from "../../js/conf/Lang.js";
import https from "../../js/https/Https.js";
import util from "../../js/util/Util.js";
import config from "@/js/conf/Config.js";
import uploadPic from "@/js/upload/UploadPic.js";
import empty from "@/components/comm/empty.vue";
import CustomerRecommend from "./CustomerRecommend.vue";
import CollectionFlowDetails from "@/components/customers/CollectionFlowDetails.vue";
import popRemainingWinTab from "@/components/comm/popRemainingWinTab.vue"; // 项目服务
import popmyCardLsWinTab from "@/components/comm/popmyCardLsWinTab.vue"; // 卡项服务
import intelligentAnalysis from "@/components/comm/intelligentAnalysis.vue"; // 智能分析

var pageSize = staticConst.PAGE_SIZE;
var pageNo = 0;
export default {
    components: {
        productSales,
        HistoricalOrders,
        CollectionFlow,
        FollowUpList,
        empty,
        CustomerRecommend,
        CollectionFlowDetails,
        popRemainingWinTab,
        popmyCardLsWinTab,
        intelligentAnalysis
    },
    props: {
        md: {
            type: [String, Number],
            default: ''
        },
        isDrawerStatus: {
            type: Boolean,
            default: false
        },
        customId: {
            type: [String, Number],
            default: ''
        },
        getYyInfoData: {
            type: Object,
            default: () => { }
        }
    },

    watch: {
        customId: {
            handler(newVal) {
                this.customerId = newVal;
            },
            deep: true,
            immediate: true,
        }
    },

    data() {
        return {
            customerId: "", //客户id
            idyun: 0, // 云店id
            dialogVisible: false,
            // 添加滚动控制相关属性
            isScrollEnabled: true, // 是否启用滚动监听
            scrollDebounceTimer: null, // 滚动防抖定时器
            tabSwitchTimer: null, // 标签切换定时器
            tabArr: [
                {
                    title: "客户跟进记录",
                    id: 1,
                    pageNo: 0,
                    list: [],
                    is_soll: false,
                    access: true,
                },
                {
                    title: "分销记录",
                    id: 8,
                    pageNo: 0,
                    list: [],
                    is_soll: false,
                    md: 15,
                    access: true,
                },
                {
                    title: "产品销售记录",
                    id: 2,
                    pageNo: 0,
                    list: [],
                    is_soll: false,
                    access: true,
                },
                {
                    title: "产品" + lang.customerTxt.historyTabTxt,
                    id: 3,
                    pageNo: 0,
                    list: [],
                    is_soll: false,
                    access: true,
                },
                {
                    title: "产品" + lang.customerTxt.collFlowTabTxt,
                    id: 4,
                    pageNo: 0,
                    list: [],
                    is_soll: false,
                    access: true,
                },
                {
                    title: '服务购买记录',
                    id: 5,
                    pageNo: 0,
                    list: [],
                    is_soll: false,
                    md: 15,
                    access: true,
                },
                {
                    title: "服务" + lang.customerTxt.historyTabTxt,
                    id: 6,
                    pageNo: 0,
                    list: [],
                    is_soll: false,
                    md: 15,
                    access: true,
                },
                {
                    title: "项目服务",
                    id: 9,
                    pageNo: 0,
                    list: [],
                    is_soll: false,
                    md: 15,
                    access: true,
                },
                {
                    title: "卡项服务",
                    id: 10,
                    pageNo: 0,
                    list: [],
                    is_soll: false,
                    md: 15,
                    access: true,
                },
                {
                    title: "智能分析",
                    id: 11,
                    pageNo: 0,
                    list: [],
                    is_soll: false,
                    md: 15,
                    access: true,
                },
                // {
                //     title: "服务" + lang.customerTxt.collFlowTabTxt,
                //     id: 7,
                //     pageNo: 0,
                //     list: [],
                //     is_soll: false,
                //     md: 15,
                // },
                // {
                //     title: lang.customerTxt.historyTabTxt,
                //     id: 6,
                //     pageNo: 0,
                //     list: [],
                //     is_soll: false,
                //     md: 15,
                // },
                // {
                //     title: lang.customerTxt.collFlowTabTxt,
                //     id: 7,
                //     pageNo: 0,
                //     list: [],
                //     is_soll: false,
                //     md: 15,
                // },
                // {
                //     title: lang.customerTxt.collFlowTabTxt,
                //     id: 8,
                //     pageNo: 0,
                //     list: [],
                //     is_soll: false,
                //     md: 15,
                // },
            ],
            curTabId: 1,
            flowDetails: {},
            txt_cat_ls: [], // 跟进类别
            add_txt_cat_ls: [], // 添加跟进记录的选择跟进类别
            ucp_ls: [], // 经手人
            followUpParam: {
                cid: "0",
                uid_cp: "0",
                t_type: "0",
            },
            listIndex: 0,
            addForm: {
                cid: "",
                imgs: [""],
                txt: "",
            },
            addFollowUpShow: false,
            addCategoryShow: false,
            itemId: "", // 分类id

            group_ls: [],
            getYunShopList: [{
                name: "全部门店",
                id: 0,
            }],
            getCustomerRecommendIndex: 1,
            customRecommendObj: {
                total_1: 0,
                total_2: 0,
                cu_info2: {},
            },
            elTagFlag: true,
        };
    },
    created() {
        this.initAccessData();
    },
    methods: {

        async initAccessData() {
            try {
                const yyLimit = await this.initAccess();
                // 找到需要设置 access 的标签项并更新
                this.tabArr.forEach(item => {
                    if ([5, 6, 9, 10, 11].includes(item.id)) {
                        item.access = yyLimit;
                    }
                });
            } catch (error) {
                this.tabArr.forEach(item => {
                    if ([5, 6, 9, 10, 11].includes(item.id)) {
                        item.access = false;
                    }
                });
            }
        },

        FollowUpListDialogIsShow(key) {
            console.log("key", key) // addCategoryShow  addFollowUpShow
            // this.$refs.FollowUpList[key] = true;
            if (this.issDrawerStatusFun()) return;
            if (key == 'addCategoryShow') {
                this.$refs.FollowUpList.addCategoryShow();
            } else if (key == 'addFollowUpShow') {
                this.$refs.FollowUpList.addFollowUpShow();
            }
        },

        issDrawerStatusFun() {
            if (this.isDrawerStatus) {
                this.$message({
                    message: '暂不支持查看/操作',
                    type: 'warning'
                });
                return true;
            } else {
                return false;
            }
        },

        handleClose() {
            this.addFollowUpShow = false;
            this.addForm = {
                cid: "",
                imgs: [""],
                txt: "",
            }
        },
        upDataFun(e) { // 跟新数据
            if (e.isArr == true) {
                this.tabArr[this.listIndex].list = [];
            }
            this.getCustomTxtLs();
        },
        // chooseImg(index){
        //     console.log(index,'indexwwqwe')
        //     let that = this;
        //     uploadPic.idyun = this.idyun;
        //     // uploadPic.activeId = 1;
        //     uploadPic.type = staticConst.UPLOAD_INTER_ACTIVE;
        //     uploadPic.uploadSussecc = uploadSuccess;
        //     uploadPic.chooseImage1(callBack);
        //     function callBack(data)
        //     {
        //         that.url = data.url;  //显示图片
        //     }

        //     function uploadSuccess(data)
        //     {
        //         that.newUploadPicSuccess(data,index)
        //     }
        // },
        addCategoryFun() {
            this.addCategoryShow = false;
        },

        // addCatSave (id) {
        //     this.itemId = id
        //     let title = this.itemId ? '编辑': '新增'
        //     this.$prompt('请输入跟进类别', title, {
        //         confirmButtonText: '确定',
        //         cancelButtonText: '取消',
        //     }).then(({ value }) => {
        //         this.addTxtCatSaveAjax(value)
        //     }).catch(() => {});
        // },
        // async addTxtCatSaveAjax (val) {
        //     let url = config.CUSTOM_TXT_CAT_SAVE;
        //     let param = {
        //         title: val,
        //         id: this.itemId
        //     }
        //     let res = await this.$api({url:url, data:param,})
        //     if (res.status == 1) {
        //         this.tabArr[this.listIndex].list = [];
        //         this.getCustomTxtLs ();
        //     }
        //     console.log(res)
        // },
        // // 删除分类
        // catDelClass (item) {
        //     this.$confirm('确定删除该跟进类别吗?', '提示', {
        //         confirmButtonText: '确定',
        //         cancelButtonText: '取消',
        //         type: 'warning'
        //     }).then(async () => {
        //         let url = config.CUSTOM_TXT_CAT_DEL
        //         let param = {
        //             id: item.id
        //         }
        //         let res = await this.$api({url: url, data: param})
        //         if(res.status == 1) {
        //             this.tabArr[this.listIndex].list = [];
        //             this.getCustomTxtLs ();
        //         }
        //     }).catch(() => {});
        // },
        // async setTxtSave () {
        //     this.addForm.customerid = this.customerId;
        //     let url = config.CUSTOM_TXT_SAVE;
        //     let copyImgs = JSON.parse(JSON.stringify(this.addForm.imgs))
        //     copyImgs = copyImgs.filter( item=> {
        //         return item
        //     })
        //     this.addForm.imgs = copyImgs;
        //     let res = await this.$api({ url: url, data: this.addForm})
        //     if (res.status == 1) {
        //         this.$message({
        //             message: '添加成功',
        //             type: 'success'
        //         });
        //         this.tabArr[this.listIndex].list = [];
        //         this.getCustomTxtLs ();
        //         this.handleClose()
        //     }
        // },
        // imgDelFun(index) {
        //     this.addForm.imgs.splice(index, 1);
        // },
        /*****新上传图片成功*****/
        // newUploadPicSuccess(result, batchid) {
        //     console.log(result,'resultresultresult')
        //     this.addForm.imgs.push(result.url)
        //     if (this.addForm.imgs.length < 9 && batchid == this.addForm.imgs.length -1) {
        //         this.addForm.imgs.push("")
        //     }
        // },
        selectFun(val, key) {
            this.tabArr[this.listIndex].list = [];
            this.followUpParam[key] = val;
            this.getCustomTxtLs()
        },
        // 查看流水详情
        async showFlowDetails(item) {
            this.$refs.dialogBillRef.open();
            this.$nextTick(() => {
                this.$refs.CollectionFlowDetailsRef.showFlowDetails(item);
            })
        },
        onClickTabItem(item, index) {
            console.log("item```", item)
            console.log("index```", index)
            console.log("this.curTabId===", this.curTabId)
            this.listIndex = index;
            if (this.curTabId == item.id) return;

            // 在切换标签时暂时禁用滚动监听，防止内容变化时误触发
            this.isScrollEnabled = false;

            // 清除之前的定时器
            if (this.tabSwitchTimer) {
                clearTimeout(this.tabSwitchTimer);
            }

            this.curTabId = item.id;
            if (this.tabArr[index].list.length == 0) {

                if (this.curTabId == 1) {
                    this.getCustomTxtLs()
                }
                else if (this.curTabId == 2 || this.curTabId == 5) {
                    this.getGdSaleList(index);
                } else if (this.curTabId == 3 || this.curTabId == 6) {
                    this.getHistoryOrdeList(index);
                } else if (this.curTabId == 4 || this.curTabId == 7) {
                    this.getCollectionFlow(index);
                } else if (this.curTabId == 8) {
                    this.tabArr[this.listIndex].list = [];
                    this.getCustomerRecommend(1);
                    // this.getYunShopLsFun()
                    this.elTagFlag = true;
                } else if (this.curTabId == 9) {
                    this.$nextTick(() => {
                        this.$refs.popRemainingWinTabRef.initData();
                    })
                } else if (this.curTabId == 10) {
                    this.$nextTick(() => {
                        this.$refs.popmyCardLsWinTabRef.initData();
                    })
                } else if (this.curTabId == 11) {
                    this.$nextTick(() => {
                        this.$refs.intelligentAnalysisRef.initAnalyInfoData();
                    })
                }
            }
            // 延迟重新启用滚动监听，给DOM变化留出时间
            this.tabSwitchTimer = setTimeout(() => {
                this.isScrollEnabled = true;
            }, 300);
        },

        async initData(id) {
            await this.clearData();
            this.customerId = id;
            this.curTabId = 1;
            this.getCustomTxtLs();
        },

        /****清除数据***/
        clearData() {
            this.customerId = "";
            this.tabArr = this.tabArr.map(item => ({
                ...item,
                pageNo: 0,
                list: []
            }));

            // 重置滚动相关状态
            this.isScrollEnabled = true;
            if (this.scrollDebounceTimer) {
                clearTimeout(this.scrollDebounceTimer);
                this.scrollDebounceTimer = null;
            }
            if (this.tabSwitchTimer) {
                clearTimeout(this.tabSwitchTimer);
                this.tabSwitchTimer = null;
            }
        },

        // 顾客跟进记录
        async getCustomTxtLs() {
            console.log(this.customerId, '333this.customerId')
            // return;
            console.log('wc?sas')
            let url = config.CUSTOM_TXT_LS;
            let param = {
                customerid: this.customerId,
            };
            Object.keys(this.followUpParam).forEach(item => {
                param[item] = this.followUpParam[item];
            })
            let res = await this.$api({ url: url, data: param })
            if (res.status == 1) {
                console.log(res)
                if (res.data) {
                    let data = res.data.txt_ls ? res.data.txt_ls : [];
                    this.tabArr[this.listIndex].list = this.tabArr[this.listIndex].list.concat(data);
                    this.txt_cat_ls = res.data.txt_cat_ls;
                    this.ucp_ls = res.data.ucp_ls;
                    this.group_ls = res.data.group_ls;
                    this.add_txt_cat_ls = JSON.parse(JSON.stringify(res.data.txt_cat_ls));
                    this.add_txt_cat_ls.shift(); // 删除数组第一位
                } else {
                    this.tabArr[this.listIndex].is_soll = true;
                }
            }
        },
        /***产品销售*****/
        getGdSaleList(index) {
            let that = this;
            let param = {};
            param.customerid = this.customerId;

            param.is_yy = this.tabArr[index].md == 15 ? 1 : 2;
            // param.is_yy = this.md == 15 ? 1 : 2;

            param.pnum = pageSize;
            param.pfrom = this.tabArr[index].pageNo * pageSize;
            https.customGoodsList(param, back);
            function back(data) {
                if (!data) return;
                if (data.status == 1) {
                    if (data.data) {
                        data = data.data;
                        console.log(that.tabArr[index], 'datadatadatadata')
                        that.tabArr[index].list = that.tabArr[index].list.concat(data);
                    } else {
                        that.tabArr[index].is_soll = true;
                    }
                }
            }
        },

        /*****历史订单*****/
        getHistoryOrdeList(index) {
            let that = this;
            let param = {};
            param.customerid = this.customerId;
            param.is_yy = this.tabArr[index].md == 15 ? 1 : 2;
            // param.is_yy = this.md == 15 ? 1 : 2;
            param.pnum = pageSize;
            param.pfrom = this.tabArr[index].pageNo * pageSize;
            https.customOrderList(param, back);
            function back(data) {
                if (!data) return;
                if (data.status == 1) {
                    if (data.data) {
                        data = data.data;
                        that.tabArr[index].list =
                            that.tabArr[index].list.concat(data);
                    } else {
                        that.tabArr[index].is_soll = true;
                    }
                }
            }
        },

        /***收款流水*****/
        getCollectionFlow(index) {
            let that = this;
            let param = {};
            param.customerid = this.customerId;
            // param.is_yy = this.md == 15 ? 1 : 2;
            param.is_yy = this.tabArr[index].md == 15 ? 1 : 2;

            param.pnum = pageSize;
            param.pfrom = this.tabArr[index].pageNo * pageSize;
            https.customBillList(param, back);
            function back(data) {
                if (!data) return;
                if (data.status == 1) {
                    if (data.data) {
                        data = data.data;
                        that.tabArr[index].list =
                            that.tabArr[index].list.concat(data);
                    } else {
                        that.tabArr[index].is_soll = true;
                    }
                }
            }
        },

        /***分销记录*****/
        // {"customerid":"10","grade":1,"idyun":"0","pfrom":"0","pnum":"20"}
        // grade=下级数，1=下一级，2=下二级
        clickTabDistr(i) {
            this.tabArr[this.listIndex].pageNo = 0;
            this.tabArr[this.listIndex].list = [];
            this.getCustomerRecommend(i);
            this.getCustomerRecommendIndex = i;
        },

        selectFunYunShop(val) {
            this.tabArr[this.listIndex].pageNo = 0;
            this.tabArr[this.listIndex].list = [];
            this.getCustomerRecommend(this.getCustomerRecommendIndex);
        },

        getCustomerRecommend(i) {
            let that = this;
            that.getYunShopList = [{
                name: "全部门店",
                id: 0,
            }]
            let param = {
                customerid: that.customerId,
                grade: i || 1,
                idyun: that.idyun,
                pfrom: that.tabArr[that.listIndex].pageNo * pageSize,
                pnum: pageSize,
            };
            https.customRecommendList(param, back);
            function back(data) {
                if (!data) return;
                if (data.status == 1) {
                    let record = data?.data;
                    if (record?.ls) {
                        that.tabArr[that.listIndex].list = that.tabArr[that.listIndex].list.concat(record?.ls);
                    } else {
                        that.tabArr[that.listIndex].is_soll = true;
                    }
                    that.customRecommendObj.total_1 = record?.total_1;
                    that.customRecommendObj.total_2 = record?.total_2;
                    that.customRecommendObj.cu_info2 = record?.cu_info2;
                    that.getYunShopList.push(...record?.yunsp_ls || []);
                }
            }
        },

        //  获取云店列表
        // async getYunShopLsFun() {
        //     let param = {}
        //     try {
        //         let res = await this.$api({ url: config.YUN_SHOP_LS, data: param })
        //         if (res.status == 1) {
        //             this.getYunShopList.push(...res.data)
        //         }
        //     } catch (error) {
        //     }
        // },

        handlerScroll() {
            // 如果滚动监听被禁用，直接返回
            if (!this.isScrollEnabled) {
                return;
            }

            // 清除之前的防抖定时器
            if (this.scrollDebounceTimer) {
                clearTimeout(this.scrollDebounceTimer);
            }

            // 使用防抖机制，避免频繁触发
            this.scrollDebounceTimer = setTimeout(() => {
                this.$nextTick(() => {
                    var flag = util.scrollData(".overflow-box");
                    if (flag) {
                        let ind = this.curTabId - 1;
                        if (this.curTabId == 2 || this.curTabId == 5) {
                            if (this.tabArr[ind].is_soll) return;
                            this.tabArr[ind].pageNo++;
                            this.getGdSaleList(ind);
                        } else if (this.curTabId == 3 || this.curTabId == 6) {
                            if (this.tabArr[ind].is_soll) return;
                            this.tabArr[ind].pageNo++;
                            this.getHistoryOrdeList(ind);
                        } else if (this.curTabId == 4 || this.curTabId == 7) {
                            if (this.tabArr[ind].is_soll) return;
                            this.tabArr[ind].pageNo++;
                            this.getCollectionFlow(ind);
                        } else if (this.curTabId == 8) {
                            if (this.tabArr[ind].is_soll) return;
                            this.tabArr[ind].pageNo++;
                            this.getCustomerRecommend(this.getCustomerRecommendIndex);
                        }
                    }
                });
            }, 100); // 100ms 防抖延迟
        },

        async initAccess() {
            return await accessCtrl.getyyLimit()
        },

    },

    mounted() {
        if (document.querySelector(".overflow-box")) {
            document.querySelector(".overflow-box").addEventListener("scroll", this.handlerScroll, true);
        }
    },

    destroyed() {
        // 清理定时器
        if (this.scrollDebounceTimer) {
            clearTimeout(this.scrollDebounceTimer);
        }
        if (this.tabSwitchTimer) {
            clearTimeout(this.tabSwitchTimer);
        }
        if (document.querySelector(".overflow-box")) {
            document.querySelector(".overflow-box").removeEventListener("scroll", this.handlerScroll);
        }
    },
};
</script>

<style lang="scss" scoped>
.FollowUpBox {
    width: 100%;
    position: relative;

    .FollowUpDiv {
        position: sticky;
        top: 0;
        background: #FFFFFF;
        z-index: 3;
        height: 40px;
    }
}


.sale-body {
    height: 400px;
    overflow: auto;

    .sale-row {
        height: 40px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 10px;
        border-bottom: 1px #f3f3f3 solid;

        &.sale_is_custom {
            cursor: pointer;

            &:hover {
                background: #fbf8f8;
            }
        }

        .sale-b-1 {
            flex: 1;
            text-align: left;
        }

        .sale-b-2 {
            flex: 1;
            text-align: center;
        }

        .sale-b-3 {
            flex: 1;
            text-align: right;
        }
    }
}
</style>
<style lang="scss">
.goods-info-txt {
    padding: 10px 0 20px 20px;

    .i-title {
        display: flex;
        margin-bottom: 6px;

        .active {
            color: #3388ff;
        }

        .item {
            cursor: pointer;
            margin-right: 10px;

            .active-s {
                width: 20px;
                margin: 0 auto;
                border-bottom: 2px solid #3388ff;
            }
        }
    }

    .no-yy-box {
        padding: 5px 10px;
        background-color: rgb(238, 243, 235);
        border-radius: 6px;
    }

    .yy-box {
        padding: 5px 10px;
        background-color: aliceblue;
        border-radius: 6px;
    }

    .overflow-box {
        overflow-y: auto;
        height: calc(100vh - 420px);
    }

    .overflow-box::-webkit-scrollbar {
        /*滚动条整体样式*/
        width: 4px;
        /*高宽分别对应横竖滚动条的尺寸*/
        height: 0px;
    }

    .overflow-box::-webkit-scrollbar-thumb {
        /*滚动条里面小方块*/
        border-radius: 10px;
        -webkit-box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.1);
        background: #ccc; //rgba(0, 0, 0, 0.0);
        scrollbar-arrow-color: red;
    }

    .overflow-box::-webkit-scrollbar-track {
        /*滚动条里面轨道*/
        -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0);
        border-radius: 0;
        background: rgba(0, 0, 0, 0);
    }
}
</style>
